﻿/*
 *  Author: Louis A. Leskoviansky
 *  Company: Artemis Solutions Group (http://www.artemis-solutions.com)
 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;

namespace AjaxControlFramework
{
    public class JsonStateStrategy : StateStrategy
    {
        //------// Properties \\--------------------------------------------\\

        //------\\ Properties //--------------------------------------------//



        //------// Constructors \\------------------------------------------\\
        public JsonStateStrategy(Control targetControl)
            : base(targetControl)
        { }
        //------\\ Constructors //------------------------------------------//



        //------// Methods \\-----------------------------------------------\\
        protected override void PersistStateToMedium(string state)
        {
            Control.AjaxContext.State["ControlState"] = state;
        }


        protected override Pair RestoreStateFromMedium()
        {
            object state = null;
            Control.AjaxContext.State.TryGetValue("ControlState", out state);

            if (!String.IsNullOrEmpty(state as string))
            {
                return (Pair)base.StateFormatter.Deserialize((string)state);
            }

            return null;
        }
        //------\\ Methods //-----------------------------------------------//
    }
}